var db;
function initDatabase(){
	db = window.openDatabase("gaprss", "1.0", "gaprssDatabase", 200000);
	db.transaction(initDB, initError, initSuccess);
	
}
function initDB(tx) {
     tx.executeSql('CREATE TABLE IF NOT EXISTS RSSCATCH (url, title,link unique,description,updated)');
    /* tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
     tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
	*/
}
function initError(err) {
    alert("Error processing SQL: "+err.code);
}
function initSuccess() {
    //alert("success!");
}
function executeSql(sql){
    //var db = window.openDatabase("gaprss", "1.0", "gaprssDatabase", 200000);
    db.transaction(
				   function(tx){
				   		tx.executeSql(sql);
				   }, function(err){
				   		alert("Error processing SQL: "+err.code);
				   });
}
/*function querySql(sql) {
   // var db = window.openDatabase("gaprss", "1.0", "gaprssDatabase", 200000);
	return db.transaction(
				   function(tx){
                   //alert();
				    	return tx.executeSql(sql, [], querySuccess, queryError);
				   },function(err){
				   		alert("Error processing SQL: "+err.code);
				   });
   
}*/
var querySql,targetUrl,callback;
function queryRSSCatch(sql,loadRssCatch,url){
    querySql = sql;
    targetUrl = url;
    callback = loadRssCatch;
    db = window.openDatabase("gaprss", "1.0", "gaprssDatabase", 200000);
    db.transaction(query,function(){alert("error")});
    
}
function query(tx){
      alert(2);
        tx.executeSql(querySql,[],success,error);
}
function success(tx,results){
        alert(3);
        callback(targetUrl,results.rows);
}